package com.nettm.leetcode;

public class ReverseInteger007 {

    public static void main(String[] args) {
        System.out.println(Integer.MIN_VALUE);
        System.out.println(ReverseInteger007.reverse(-2147483648));
    }

    public static int reverse(int x) {
        int result = 0;
        int tmp = x;
        while (tmp != 0) {
            if (result > Integer.MAX_VALUE / 10 || result < Integer.MIN_VALUE / 10) {
                result = 0;
                break;
            }

            result *= 10;
            int a = tmp / 10;
            int b = tmp % 10;
            tmp = a;
            result += b;
            System.out.println(result);
        }
        return result;
    }
}
